<?php

namespace api\wechat;

//意见建议类
use utils\base64_to_file;
use utils\oss;

class advance
{
    //上传
    public function up($data){
        $con=con();
        $openid=$data['openid'];
        $content=$data['content'];
        $img=$data['img'];
        $date=date('Y-m-d');
        $url=[];

        $user_id=mysqli_query($con,"select * from user where openid='$openid' ");
        $user_id=mysqli_fetch_all($user_id,true);
        if(count($user_id)==0){
            mysqli_close($con);
            return out_error('查无此人！');
        }
        $user_id=(int)$user_id[0]['id'];

        for($i=0;$i<count($img);$i++){
            $file=base64_to_file::get("",$img[$i]["file_name"],$img[$i]["file"]);
            $res=oss::upload("advance/$date/".$file["name"],$file["path"]);
            $url[]=$res["info"]["url"];
        }
        $url=implode(',',$url);
        $time=time();
        $res=mysqli_query($con,"insert into advance(content,img_url,user_id,create_time,update_time) values('$content','$url',$user_id,$time,$time)");
        mysqli_close($con);
        if($res){
            return out_right();
        }else{
            return out_error('意见反馈失败！');
        }
    }
}